package com.example.photography.adapter.community;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.photography.R;
import com.example.photography.bean.CommunityBean;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class Community_ActAdapter extends RecyclerView.Adapter<Community_ActAdapter.ViewHolder> {
    private final Context context;
    private List<CommunityBean.DataBean.ActivityBean> activityBeans;

    public Community_ActAdapter(Context context, List<CommunityBean.DataBean.ActivityBean> activityBeans) {
        this.context = context;
        this.activityBeans = activityBeans;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.act_community, parent, false);

        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.svCover.setImageURI(Uri.parse(activityBeans.get(position).getActivity_cover()));
        holder.actName.setText(activityBeans.get(position).getActivity_name());
        holder.actHost.setText(activityBeans.get(position).getActivity_host());
    }

    @Override
    public int getItemCount() {
        return activityBeans == null ? 0 : activityBeans.size();
    }

    static
    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.sv_cover)
        SimpleDraweeView svCover;
        @BindView(R.id.act_name)
        TextView actName;
        @BindView(R.id.act_host)
        TextView actHost;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
